package controller

import (
	"GoAdmin/models"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
	"xorm.io/builder"
)

// ExaminerList 考核员列表
func ExaminerList(c *gin.Context) {
	var (
		err error
	)
	page, _ := strconv.Atoi(c.DefaultPostForm("page", "1"))
	pageSize, _ := strconv.Atoi(c.DefaultPostForm("pageSize", "15"))
	offset := (page - 1) * pageSize
	filter := builder.NewCond()
	schoolId := c.PostForm("school_id")
	if username := c.PostForm("name"); username != "" {
		filter = filter.And(builder.Like{"u.name", username})
	}
	if phone := c.PostForm("phone"); phone != "" {
		filter = filter.And(builder.Like{"u.phone", phone})
	}
	if status := c.PostForm("status"); status != "" {
		filter = filter.And(builder.Eq{"c.status": status})
	}
	list, count, err := new(models.Examiner).GetExaminerList(schoolId, filter, pageSize, offset)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{"code": 201, "msg": "fail"})
		return
	}
	fmt.Println("!!!")
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "获取考核员列表成功", "data": map[string]interface{}{"list": list, "Count": count}})
	return
}
